=> PUBLISHER_THEME_URI . 'images/shortcodes/bs-thumbnail-listing-1.png', ) ); } // page_builder_settings } // Publisher_Thumbnail_Listing_1_Shortcode /** * Publisher Thumbnail Listing 1 Widget */ class Publisher_Thumbnail_Listing_1_Widget extends Publisher_Theme_Listing_Widget { /** * Register widget. */ function __construct() { $this->defaults['columns'] = 1; parent::__construct( 'bs-thumbnail-listing-1', __( 'Listing - Thumbnail 1', 'publisher' ), array( 'description' => __( 'Widget for Thumbnail Listing 1', 'publisher' ) ) ); } /** * Adds backend fields */ function load_fields() { // Back end form fields $this->fields = array_merge( array( array( 'name' => '', 'id' => '_help_img', 'type' => 'image_preview', 'std' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-thumbnail-listing-1-big-widget.png', ), array( 'name' => __( 'Widget Title', 'publisher' ), 'id' => 'title', 'type' => 'text', ), ), $this->fields_map_listing_filters(), $this->fields_map_listing_tabs(), $this->fields_map_listing_pagination(), $this->fields_map_listing_design() ); } /** * Loads widget -> shortcode default attrs */ public function load_defaults() { if ( $this->defaults_loaded ) { return; } $this->defaults_loaded = true; $this->defaults = BF_Shortcodes_Manager::factory( $this->base_widget_id, [], true )->defaults; $this->defaults['paginate'] = 'next_prev'; $this->defaults['pagination-show-label'] = 1; $this->defaults['columns'] = 1; $this->defaults['listing-settings'] = publisher_get_option( $this->get_listing_option_id() ); } } /** * BS Thumbnail Listing 2 Shortcode */ class Publisher_Thumbnail_Listing_2_Shortcode extends Publisher_Theme_Listing_Shortcode { function __construct( $id, $options ) { $id = 'bs-thumbnail-listing-2'; $_options = array( 'defaults' => array( 'title' => '', 'hide_title' => 0, 'icon' => '', 'category' => '', 'tag' => '', 'post_ids' => '', 'post_type' => '', 'offset' => '', 'count' => 4, 'order_by' => 'date', 'order' => 'DESC', 'time_filter' => '', 'style' => 'listing-thumbnail-2', 'columns' => 2, 'tabs' => false, 'tabs_cat_filter' => '', ), 'have_widget' => true, 'have_vc_add_on' => true, 'have_gutenberg_add_on' => true, ); if ( isset( $options['shortcode_class'] ) ) { $_options['shortcode_class'] = $options['shortcode_class']; } if ( isset( $options['widget_class'] ) ) { $_options['widget_class'] = $options['widget_class']; } add_filter( 'publisher-theme-core/pagination/filter-data/' . __CLASS__, array( $this, 'append_required_atts' ) ); parent::__construct( $id, $_options ); } /** * Adds this listing custom atts to bs_pagin * * @return array */ public function append_required_atts( $atts ) { $atts[] = 'columns'; $atts[] = 'override-listing-settings'; $atts[] = 'listing-settings'; return $atts; } /** * Display the inner content of listing * * @param string $atts Attribute of shortcode or ajax action * @param string $tab Tab * @param string $pagin_button Ajax action button */ function display_content( &$atts, $tab = '', $pagin_button = '' ) { // Process block level add and set props publisher_process_listing_block_ad( $atts ); $_check = array( 'more_btn' => '', 'infinity' => '', 'more_btn_infinity' => '', ); if ( isset( $_check[ $pagin_button ] ) ) { publisher_set_prop( 'show-listing-wrapper', false ); $atts['bs-pagin-add-to'] = '.listing'; $atts['bs-pagin-add-type'] = 'append'; } unset( $_check ); // Clear memory // Change title tag to p for adding more priority to content heading tags. if ( bf_get_current_sidebar() || publisher_inject_location_get_status() ) { publisher_set_blocks_title_tag( 'p' ); } // Set columns if ( isset( $atts['columns'] ) ) { $atts = publisher_improve_block_atts_for_size( $atts, 'medium-columns' ); publisher_set_prop( 'listing-class', sprintf( 'scolumns-%d %s', $atts['columns'], publisher_get_block_size_class() ) ); publisher_set_prop( 'listing-columns', $atts['columns'] ); } publisher_get_view( 'loop', 'listing-thumbnail-2' ); } public function get_fields() { return array_merge( array( array( 'type' => 'tab', 'name' => __( 'Style', 'publisher' ), 'id' => 'style', ), array( 'name' => __( 'Columns', 'publisher' ), 'id' => 'columns', // 'type' => 'select', 'options' => array( '1' => __( '1 Column', 'publisher' ), '2' => __( '2 Column', 'publisher' ), '3' => __( '3 Column', 'publisher' ), '4' => __( '4 Column', 'publisher' ), '5' => __( '5 Column', 'publisher' ), ), // 'vc_admin_label' => true, ), ), parent::get_fields(), parent::block_ad_fields() ); } /** * Registers Page Builder Add-on */ function page_builder_settings() { $settings = parent::page_builder_settings(); return array_merge( $settings, array( "name" => __( 'Thumbnail 2', 'publisher' ), "base" => $this->id, "weight" => 10, "wrapper_height" => 'full', "category" => publisher_white_label_get_option( 'publisher' ), 'icon_url' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-thumbnail-listing-2.png', ) ); } // page_builder_settings } // Publisher_Thumbnail_Listing_2_Shortcode /** * Publisher Thumbnail Listing 2 Widget */ class Publisher_Thumbnail_Listing_2_Widget extends Publisher_Theme_Listing_Widget { /** * Register widget. */ function __construct() { parent::__construct( 'bs-thumbnail-listing-2', __( 'Listing - Thumbnail 2', 'publisher' ), array( 'description' => __( 'Widget for Thumbnail Listing 2', 'publisher' ) ) ); } /** * Adds backend fields */ function load_fields() { // Back end form fields $this->fields = array_merge( array( array( 'name' => '', 'id' => '_help_img', 'type' => 'image_preview', 'std' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-thumbnail-listing-2-big-widget.png', ), array( 'name' => __( 'Widget Title', 'publisher' ), 'id' => 'title', 'type' => 'text', ), array( 'type' => 'select', 'name' => __( 'Columns', 'publisher' ), 'id' => 'columns', 'options' => array( '1' => __( '1 Column', 'publisher' ), '2' => __( '2 Column', 'publisher' ), ), ), ), $this->fields_map_listing_filters(), $this->fields_map_listing_tabs(), $this->fields_map_listing_pagination(), $this->fields_map_listing_design() ); } /** * Loads widget -> shortcode default attrs */ public function load_defaults() { if ( $this->defaults_loaded ) { return; } $this->defaults_loaded = true; $this->defaults = BF_Shortcodes_Manager::factory( $this->base_widget_id, [], true )->defaults; // Set columns if ( isset( $atts['columns'] ) ) { $atts = publisher_improve_block_atts_for_size( $atts ); publisher_set_prop( 'listing-class', sprintf( 'columns-%d', $atts['columns'] ) ); publisher_set_prop( 'listing-columns', $atts['columns'] ); } $this->defaults['paginate'] = 'next_prev'; $this->defaults['pagination-show-label'] = 1; $this->defaults['listing-settings'] = publisher_get_option( $this->get_listing_option_id() ); } } /** * Publisher Thumbnail Listing 3 Shortcode */ class Publisher_Thumbnail_Listing_3_Shortcode extends Publisher_Theme_Listing_Shortcode { function __construct( $id, $options ) { $id = 'bs-thumbnail-listing-3'; $_options = array( 'defaults' => array( 'title' => '', 'hide_title' => 0, 'icon' => '', 'category' => '', 'tag' => '', 'post_ids' => '', 'post_type' => '', 'offset' => '', 'count' => 4, 'order_by' => 'date', 'order' => 'DESC', 'time_filter' => '', 'style' => 'listing-thumbnail-3', 'columns' => 2, 'tabs' => false, 'tabs_cat_filter' => '', ), 'have_widget' => true, 'have_vc_add_on' => true, 'have_gutenberg_add_on' => true, ); if ( isset( $options['shortcode_class'] ) ) { $_options['shortcode_class'] = $options['shortcode_class']; } if ( isset( $options['widget_class'] ) ) { $_options['widget_class'] = $options['widget_class']; } add_filter( 'publisher-theme-core/pagination/filter-data/' . __CLASS__, array( $this, 'append_required_atts' ) ); parent::__construct( $id, $_options ); } /** * Adds this listing custom atts to bs_pagin * * @return array */ public function append_required_atts( $atts ) { $atts[] = 'columns'; $atts[] = 'override-listing-settings'; $atts[] = 'listing-settings'; return $atts; } /** * Display the inner content of listing * * @param string $atts Attribute of shortcode or ajax action * @param string $tab Tab * @param string $pagin_button Ajax action button */ function display_content( &$atts, $tab = '', $pagin_button = '' ) { // Process block level add and set props publisher_process_listing_block_ad( $atts ); $_check = array( 'more_btn' => '', 'infinity' => '', 'more_btn_infinity' => '', ); if ( isset( $_check[ $pagin_button ] ) ) { publisher_set_prop( 'show-listing-wrapper', false ); $atts['bs-pagin-add-to'] = '.listing'; $atts['bs-pagin-add-type'] = 'append'; } unset( $_check ); // Clear memory // Change title tag to p for adding more priority to content heading tags. if ( bf_get_current_sidebar() || publisher_inject_location_get_status() ) { publisher_set_blocks_title_tag( 'p' ); } // Set columns if ( isset( $atts['columns'] ) ) { $atts = publisher_improve_block_atts_for_size( $atts ); publisher_set_prop( 'listing-class', sprintf( 'columns-%d', $atts['columns'] ) ); publisher_set_prop( 'listing-columns', $atts['columns'] ); } publisher_get_view( 'loop', 'listing-thumbnail-3' ); } public function get_fields() { return array_merge( array( array( 'type' => 'tab', 'name' => __( 'Style', 'publisher' ), 'id' => 'style', ), array( 'name' => __( 'Columns', 'publisher' ), 'id' => 'columns', // 'type' => 'select', 'options' => array( '1' => __( '1 Column', 'publisher' ), '2' => __( '2 Column', 'publisher' ), '3' => __( '3 Column', 'publisher' ), '4' => __( '4 Column', 'publisher' ), ), // 'vc_admin_label' => true, ), ), parent::get_fields(), parent::block_ad_fields() ); } /** * Registers Page Builder Add-on */ function page_builder_settings() { $settings = parent::page_builder_settings(); return array_merge( $settings, array( "name" => __( 'Thumbnail 3', 'publisher' ), "base" => $this->id, "description" => __( '1 to 4 Column', 'publisher' ), "weight" => 10, "wrapper_height" => 'full', "category" => publisher_white_label_get_option( 'publisher' ), 'icon_url' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-thumbnail-listing-3.png', ) ); } // page_builder_settings } // Publisher_Thumbnail_Listing_3_Shortcode /** * Publisher Thumbnail Listing 3 Widget */ class Publisher_Thumbnail_Listing_3_Widget extends Publisher_Theme_Listing_Widget { /** * Register widget. */ function __construct() { parent::__construct( 'bs-thumbnail-listing-3', __( 'Listing - Thumbnail 3', 'publisher' ), array( 'description' => __( 'Widget for Thumbnail Listing 3', 'publisher' ) ) ); } /** * Adds backend fields */ function load_fields() { // Back end form fields $this->fields = array_merge( array( array( 'name' => '', 'id' => '_help_img', 'type' => 'image_preview', 'std' => PUBLISHER_THEME_URI . 'images/shortcodes/bs-thumbnail-listing-3-big-widget.png', ), array( 'name' => __( 'Widget Title', 'publisher' ), 'id' => 'title', 'type' => 'text', ), ), $this->fields_map_listing_filters(), $this->fields_map_listing_tabs(), $this->fields_map_listing_pagination(), $this->fields_map_listing_design() ); } /** * Loads widget -> shortcode default attrs */ public function load_defaults() { if ( $this->defaults_loaded ) { return; } $this->defaults_loaded = true; $this->defaults = BF_Shortcodes_Manager::factory( $this->base_widget_id, [], true )->defaults; $this->defaults['paginate'] = 'next_prev'; $this->defaults['pagination-show-label'] = 1; $this->defaults['columns'] = 1; $this->defaults['listing-settings'] = publisher_get_option( $this->get_listing_option_id() ); } } unction get_permission_callback( $request ) { $is_multi = (bool) $request->get_param( 'is_multi' ); $result = false; // The function is public since endpoint need to access it. // Utilize 'WP_REST_Controller' get_permission_check methods. switch ( $request->get_method() ) { case 'GET': $result = $is_multi ? $this->get_items_permissions_check( $request ) : $this->get_item_permissions_check( $request ); break; case 'POST': $result = $is_multi ? $this->create_items_permissions_check( $request ) : $this->create_item_permissions_check( $request ); break; case 'UPDATE': case 'PUT': case 'PATCH': $result = $is_multi ? $this->update_items_permissions_check( $request ) : $this->update_item_permissions_check( $request ); break; case 'DELETE': $result = $is_multi ? $this->delete_items_permissions_check( $request ) : $this->delete_item_permissions_check( $request ); break; } if ( $result instanceof \WP_Error ) { throw new WP_Error_Exception( $result ); } return $result; } /** * Checks if a given request has access to create items. ** * * @param \WP_REST_Request $request Full details about the request. * * @return true|\WP_Error True if the request has access to create items, WP_Error object otherwise. */ public function create_items_permissions_check( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Checks if a given request has access to update items. * * @param \WP_REST_Request $request Full details about the request. * * @return true|\WP_Error True if the request has access to update the item, WP_Error object otherwise. */ public function update_items_permissions_check( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Checks if a given request has access to delete items. * * @param \WP_REST_Request $request Full details about the request. * * @return true|\WP_Error True if the request has access to delete the item, WP_Error object otherwise. */ public function delete_items_permissions_check( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } public function get_items( $request ) { return $this->get_controller_index(); } /** * Creates multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ public function create_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Updates multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ public function update_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Delete multiple items. * * @param \WP_REST_Request $request Full data about the request. * * @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure. */ public function delete_items( $request ) { return new \WP_Error( 'invalid-method', sprintf( "Method '%s' not implemented. Must be overridden in subclass.", __METHOD__ ), [ 'status' => 405 ] ); } /** * Get the parent controller. * * @return \Elementor\Data\V2\Base\Controller|null */ public function get_parent() { return $this->parent; } /** * Get sub controller(s). * * @return \Elementor\Data\V2\Base\Controller[] */ public function get_sub_controllers() { return $this->sub_controllers; } /** * Get processors. * * @param string $command * * @return \Elementor\Data\V2\Base\Processor[] */ public function get_processors( $command ) { $result = []; if ( isset( $this->processors[ $command ] ) ) { $result = $this->processors[ $command ]; } return $result; } /** * Register processors. */ public function register_processors() { } /** * Register index endpoint. */ protected function register_index_endpoint() { if ( ! $this->parent ) { $this->register_endpoint( new Endpoint\Index( $this ) ); return; } $this->register_endpoint( new Endpoint\Index\Sub_Index_Endpoint( $this ) ); } /** * Register endpoint. * * @param \Elementor\Data\V2\Base\Endpoint $endpoint * * @return \Elementor\Data\V2\Base\Endpoint */ protected function register_endpoint( Endpoint $endpoint ) { $command = $endpoint->get_full_command(); if ( $endpoint instanceof Endpoint\Index ) { $this->index_endpoint = $endpoint; } else { $this->endpoints[ $command ] = $endpoint; } $format = $endpoint->get_format(); // `$e.data.registerFormat()`. Manager::instance()->register_endpoint_format( $command, $format ); return $endpoint; } /** * Register a processor. * * That will be later attached to the endpoint class. * * @param Processor $processor * * @return \Elementor\Data\V2\Base\Processor $processor_instance */ protected function register_processor( Processor $processor ) { $command = $processor->get_command(); if ( ! isset( $this->processors[ $command ] ) ) { $this->processors[ $command ] = []; } $this->processors[ $command ] [] = $processor; return $processor; } /** * Register. * * Endpoints & processors. */ protected function register() { $this->register_index_endpoint(); $this->register_endpoints(); // Aka hooks. $this->register_processors(); } /** * Get collection params by 'additionalProperties' context. * * @param string $context * * @return array */ protected function get_collection_params_by_additional_props_context( $context ) { $result = []; $collection_params = $this->get_collection_params(); foreach ( $collection_params as $collection_param_key => $collection_param ) { if ( isset( $collection_param['additionalProperties']['context'] ) && $context === $collection_param['additionalProperties']['context'] ) { $result[ $collection_param_key ] = $collection_param; } } return $result; } /** * When `$this->get_parent_name` is extended, the controller will have a parent, and will know to behave like a sub-controller. * * @param string $parent_name */ private function act_as_sub_controller( $parent_name ) { $this->parent = Manager::instance()->get_controller( $parent_name ); if ( ! $this->parent ) { trigger_error( "Cannot find parent controller: '$parent_name'", E_USER_ERROR ); // phpcs:ignore } $this->parent->sub_controllers [] = $this; } /** * Controller constructor. * * Register endpoints on 'rest_api_init'. */ public function __construct() { $this->namespace = static::get_default_namespace() . '/v' . static::get_default_version(); $this->rest_base = $this->get_name(); add_action( 'rest_api_init', function () { $this->register(); // Because 'register' is protected. } ); /** * Since all actions were removed for custom internal REST server. * Re-add the actions. */ add_action( 'elementor_rest_api_before_init', function () { add_action( 'rest_api_init', function () { $this->register(); } ); } ); $parent_name = $this->get_parent_name(); if ( $parent_name ) { $this->act_as_sub_controller( $parent_name ); } } }